﻿using Gateway.Domain.EFCore.Configuration;
using Gateway.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Gateway.Domain.Configuration;

public class RoleExtensionPermissionConfiguration : EntityConfiguration<RoleExtensionPermission>
{
    public override void Configure(EntityTypeBuilder<RoleExtensionPermission> builder)
    {
        builder.ToTable(t => t.HasComment("角色扩展权限配置表"));
        builder.Property(x => x.RoleId).IsRequired().HasMaxLength(36).HasComment("角色标识");
        builder.Property(x => x.AuthType).IsRequired().HasMaxLength(100)
            .HasComment("权限类型 数据权限   data   控制台模块 dashboardmodule  控制台  dashboard");
        builder.Property(x => x.AuthKey).IsRequired().HasMaxLength(200).HasComment("扩展权限对应的key");
        builder.Property(x => x.AuthValue).IsRequired().HasMaxLength(2000).HasComment("扩展权限对应的值");
        builder.HasOne(x => x.Role).WithMany(x => x.RoleExtensionPermissions).HasForeignKey(x => x.RoleId)
            .OnDelete(DeleteBehavior.Cascade);
        base.Configure(builder);
    }
}